package com.sangeng.controller;

import com.sangeng.annotation.SystemLog;
import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.constants.SystemConstants;
import com.sangeng.domain.entity.Comment;
import com.sangeng.service.CommentService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 评论表(Comment)表控制层
 *
 * @author makejava
 * @since 2024-08-16 20:35:56
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论表", description = "评论表相关接口")
public class CommentController {
    /**
     * 服务对象
     */
    @Resource
    private CommentService commentService;

    //查询评论列表接口
    @SystemLog(businessName = "查询评论列表")
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize){

        if (articleId==0){
            throw new RuntimeException("评论获取失败");
        }
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT, articleId,pageNum,pageSize);

    }


    //查询友链评论接口
    @SystemLog(businessName = "查询友链评论")
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){

        return commentService.commentList(SystemConstants.LINK_COMMENT, null,pageNum,pageSize);
    }

    //发表评论接口
    @SystemLog(businessName = "发表评论")
    @PostMapping()
    public ResponseResult addComment(@RequestBody Comment comment){
        return commentService.addComment(comment);
    }


}

